package org.doubango.FrCall.Screens;

import java.util.ArrayList;
import java.util.HashMap;

import org.doubango.FrCall.Engine;
import org.doubango.FrCall.R;
import org.doubango.FrCall.Services.IScreenService;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.Intents;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class ScreenContactsPage extends BaseScreen {
	
	private static final String TAG = BaseScreen.class.getCanonicalName();
	private final IScreenService mScreenService;
	
	private ListView contactsList;
	private Button toFriendsPage;
	private Button toHistoryCall;
	private Button toAdd;
	public ScreenContactsPage( ) {
		super(SCREEN_TYPE.CONTACTS_PAGE, TAG);
		mScreenService = ((Engine)Engine.getInstance()).getScreenService();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.screen_contacts_page);
		contactsList = (ListView) findViewById(R.id.show_contacts);
		toFriendsPage = (Button) findViewById(R.id.con_page_fri);
		toHistoryCall = (Button) findViewById(R.id.to_history_call);
		toAdd=(Button) findViewById(R.id.to_add);
		HashMap<String, String> contactsListMap = new HashMap<String, String>();
		contactsListMap.put("contactsName", "舒义海");
		contactsListMap.put("contactsNumber", "18013575438");
		ArrayList<HashMap<String, String>> contactsListData = new ArrayList<HashMap<String,String>>();
		for(int i = 0;i<10;i++){
			contactsListData.add(contactsListMap);
		}
		SimpleAdapter contactsListAdapter = new SimpleAdapter(this, contactsListData, R.layout.screen_contacts_item, new String[]{"contactsName","contactsNumber"}, new int[]{R.id.con_name,R.id.con_num});
		contactsList.setAdapter(contactsListAdapter);
		
		ContactsButtonListener contactsButtonListener = new ContactsButtonListener();
		toFriendsPage.setOnClickListener(contactsButtonListener);
		toHistoryCall.setOnClickListener(contactsButtonListener);
		toAdd.setOnClickListener(contactsButtonListener);
		contactsList.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Intent intent = new Intent(ScreenContactsPage.this ,DialPage.class);
				startActivity(intent);
//				contactsFlipper.setDisplayedChild(1);
			}
		});
	}
	public class ContactsButtonListener implements OnClickListener{

		@Override
		public void onClick(View v) {
			if(v == toFriendsPage){
				mScreenService.show(ScreenFriendList.class);
			}else if(v == toHistoryCall){
				mScreenService.show(ScreenHistoryCall.class);
			}else if(v==toAdd){
				mScreenService.show(ScreenTabDialer.class);
			}
		}
		
	}
    
}
